<?php
/**
 * MatchDart! is a darts event ranking table component for joomla
 * 
 * @version		2.0.1 | $Id: venues.php 92 2009-08-28 10:34:11Z mwi.nor $
 * @package		MatchDart!
 * @subpackage	Admin
 * @copyright	Copyright (C) 2005 - 2009 Marco Wilde. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * @author		Marco Wilde, <mailto://info@matchdart.de>
 * @link		http://www.matchdart.de
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class MatchdartControllerVenues extends JController
{
    public function __construct()
    {
        parent::__construct();

        // Register Extra tasks
        $this->registerTask( 'add', 'edit' );
    }

    public function edit()
    {
        JRequest::setVar('view','venue');
        JRequest::setVar('layout','form');
        JRequest::setVar('hidemainmenu', 1);

        parent::display();
    }

    public function save()
    {
        JRequest::checkToken() or jexit( 'Invalid Token' );
        $model = $this->getModel( 'venue' );

        if ($model->store()) {
            $msg = JText::_( 'MD_OPERATION_SAVE' );
            $type = 'message';
        } else {
            $msg = JText::_( 'MD_OPERATION_SAVEERR' );
            $type = 'error';
        }

        $this->setRedirect( 'index.php?option=com_matchdart&controller=venues', $msg, $type );
    }

    public function remove()
    {
        JRequest::checkToken() or jexit( 'Invalid Token' );
        //Load model and delete entry - redirect afterwards
        $model = $this->getModel( 'venue' );
        if(!$model->delete()) {
            $msg = JText::_( 'MD_OPERATION_DELETEERR' );
            $type = 'error';
        } else {
            $msg = JText::_( 'MD_OPERATION_DELETE' );
            $type = 'message';
        }
        $this->setRedirect( JRoute::_( 'index.php?option=com_matchdart&controller=venues', false ), $msg, $type );
    }

    public function cancel()
    {
        $msg = JText::_( 'MD_OPERATION_CANCEL' );
        $this->setRedirect( 'index.php?option=com_matchdart&controller=venues', $msg, 'notice' );
    }

    public function display()
    {
        JRequest::setVar( 'view', 'venues' );
        parent::display();
    }
}
?>